/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.Impl;

import java.util.Date;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import models.Comments;
import models.Users;
import services.interfaces.ICommentService;

/**
 *
 * @author milokokok
 */

@Stateless
@LocalBean

public class CommentsServiceImpl extends GenericServiceImpl<Comments> implements ICommentService {

    @PersistenceContext(unitName="orsPU")
    private EntityManager em;
    
    public CommentsServiceImpl() {
        super(Comments.class);
    }
    
    @Override
    protected EntityManager getEntityManager() {
        return this.em;
    }

//    @Override
    public Comments getCommentsByIdUser(int idUser) {
        Query q = em.createNamedQuery("Comments.findByIdUser").setParameter("idUser", idUser);
        Comments c = (Comments)q.getSingleResult();
        return c;
    }

    @Override
    public Comments getCommentsByDatePublished(Date datePublished) {
        Query q = em.createNamedQuery("Comments.findByDatePublished").setParameter("datePublished", datePublished);
        Comments c = (Comments)q.getSingleResult();
        return c;
    }
    
}
